-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle empty module on the course structure saving #7649
Conversation
Test the previous changes of this PR with WordPress Playground. |
WordPress Dependencies ReportThe
This comment was automatically generated by the |
e80cc03
to
8eab758
Compare
Test the previous changes of this PR with WordPress Playground. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just added two small comments.
} | ||
|
||
// Ignore items that are not modules or have a title already. | ||
if ( 'module' !== $item['type'] || ! empty( $item['title'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Just an edge case as we are trying to work against user-made scenarios - can we trim the title and then check if it's empty? Because otherwise, it doesn't assign a name to the module if the title is just one or more spaces. Does it make sense?
@@ -230,7 +230,8 @@ private function get_modules(): array { | |||
* @return bool|WP_Error | |||
*/ | |||
public function save( array $raw_structure ) { | |||
$structure = $this->sanitize_structure( $raw_structure ); | |||
$raw_structure = $this->ensure_modules_have_names( $raw_structure ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this check become redundant now?
sensei/includes/class-sensei-course-structure.php
Lines 897 to 902 in 53dbffa
if ( 'module' === $raw_item['type'] ) { | |
return new WP_Error( | |
'sensei_course_structure_modules_missing_title', | |
__( 'Please ensure all modules have a name before saving.', 'sensei-lms' ) | |
); | |
} |
Hey! 👋 |
Thanks for raising it @renatho !
It was exactly my thought and I agree it would be better (That's why my suggestion here p1722358285119989/1722355438.888029-slack-C02NWDZBL0H was to add the names before "triggering" save, we trigger a save during the tour). I thought about commenting the same here, but later thought as this is already implemented, it'd make us re-do the whole thing, that's why I approved it, thinking about the cost vs. benefit. But I would've preferred doing it only for the tour to keep the flow of the tour smooth and errorless, and enforce user to explicitly give modules a Title as before and not saving otherwise in rest of the cases. |
Yes, initially tried to do that on the frontend, but didn't find a proper way to update titles, and switched to a more straightforward solution. Also, speaking about the frontend, I noticed that we only show the error message at the top of the screen, but don't even highlight the fields that require user's action (and I think because of placeholders it might not be obvious for some users). So I was thinking that setting the default title on the backend is a quick solution to this problem as well as it forgives some user mistakes, and we don't need to work on UX and design for that. I'm going to look maybe for a quick dirty solution for the approach Imran suggested. |
Resolves #7625
The problem described in the issue happens when, while following the tour, the user doesn't set the module title.
The course structure can't be saved in this case, and it causes the issue that the expected “Edit Lesson” link doesn't appear in the toolbar.
Proposed Changes
Testing Instructions
Pre-Merge Checklist